/*
 * (c) LOIS, Ltd., 2004
 * 
 * $Id: MySqlDbLogin.java,v 1.1 2011/01/29 11:01:52 dell Exp $
 */
package ru.jexp.tl.db.mysql;

import oracle.toplink.sessions.DatabaseLogin;
import oracle.toplink.sessions.DefaultConnector;

import com.mysql.jdbc.Driver;

public class MySqlDbLogin extends DatabaseLogin {
	public static final MySqlDbLogin TEST = new MySqlDbLogin("root", "root",
			MySqlURL.TEST);

	public static final MySqlDbLogin WORK = new MySqlDbLogin("root", "root",
			MySqlURL.WORK);

	private MySqlURL url;

	public MySqlDbLogin(String userName, String password, MySqlURL url) {
		this(userName, password, url, null);
	}

	public MySqlDbLogin(String userName, String password, MySqlURL url,
			String characterEncoding) {
		super(new MySqlPlatform());
		this.url = url;
		setUserName(userName);
		setPassword(password);
		setDriverClass(Driver.class);
		setConnectionString(url.getURL());
		setShouldBindAllParameters(true);
		setShouldCacheAllStatements(true);
		setUsesByteArrayBinding(true);
		setUsesStringBinding(true);
		if (shouldUseByteArrayBinding()) {
			setUsesStreamsForBinding(false);
		}
		setShouldForceFieldNamesToUpperCase(false);
		setShouldOptimizeDataConversion(false);
		setShouldTrimStrings(true);
		setUsesBatchWriting(false);
		if (shouldUseBatchWriting()) {
			setUsesJDBCBatchWriting(true);
		}
		setUsesExternalConnectionPooling(false);
		setUsesExternalTransactionController(false);
		setConnector(new MySqlConnector((DefaultConnector) getConnector(),
				characterEncoding));
	}

	public MySqlURL getURL() {
		return url;
	}
}
